Repository navigation
Parse OpenSSL versions without strings.SplitN - #72
Merged
Merged
Conversation
parseOpenSSLVersion now takes the major and minor components with nextDotPart instead of splitting the version into a slice, so compareOpenSSL no longer allocates. refParseOpenSSLVersion keeps the old parser, and the new one is checked against it on the parity corpus plus OpenSSL forms, the conformance fixtures and a fuzz target. OpenSSL joins BenchmarkCompareWithScheme and TestEcosystemComparatorsDoNotAllocate. Refs git-pkgs#31 Co-authored-by: Claude <noreply@anthropic.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
andrew
approved these changes
Dec 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #31, the OpenSSL item.
parseOpenSSLVersionsplit the version withstrings.SplitN(s, ".", 3), which allocates the parts slice on every call, twice per comparison. It now takes major and minor withnextDotPart, the same helpercompareIntDotuses, and keeps the rest of the string as the third component. The rules after the split are unchanged: digit-only major and minor, and a third component that starts with digits, with the remainder as the patch letters or-alpha/-betasuffix.The
moreresults ofnextDotPartare ignored on purpose. When the version has fewer than two dots,restcomes back empty and the existing "third component must start with a digit" check rejects it, which is whatlen(parts) != 3did before. Mutation testing flagged explicitmorechecks as dead code, and the fuzz target below agrees.go test -bench 'BenchmarkCompareWithScheme/OpenSSL' -benchmem, Go 1.26.7, linux/amd64, before and after run alternately (3 rounds of-count 3, so 9 runs each) on a slow, busy 2-core machine. Read the ratio, not the absolute numbers:1.1.1wvs1.1.1kThe row is new in
BenchmarkCompareWithScheme.Coverage follows the IntDot change:
openssl_reference_test.gois a renamed copy of the oldparseOpenSSLVersion.TestParseOpenSSLVersionMatchesReferencecompares the parsed struct and the ok flag on the shared parity corpus plus OpenSSL forms: letter patches,-alpha/-beta/-pre, 3.x, missing, leading, doubled and extra dots, leading zeros, spaces and a non-ASCII digit.TestParseOpenSSLVersionMatchesReferenceOnFixturesdoes the same for the conformance fixtures.FuzzParseOpenSSLVersionMatchesReferenceran 60 s here twice (370k and 191k execs), with no difference.TestEcosystemComparatorsDoNotAllocate, a letter patch and a prerelease. Both fail on main with 2 allocations.Mutations, one at a time, in a separate worktree: no digit check on major, no digit check on minor, minor taken from the start of the string, major and minor swapped, the patch keeping its digits, and an empty third component accepted. All 6 turn a test red.
The 3.x path still goes through
compareSemver, which this doesn't touch.go test ./...ok,golangci-lint run0 issues,go vetok, gofmt clean.